//
//  HomeTableViewCell.m
//  知乎
//
//  Created by 陶薇 on 2017/10/20.
//  Copyright © 2017年 Liaochengshu. All rights reserved.
//

#import "HomeTableViewCell.h"
@interface HomeTableViewCell()
@property (nonatomic,strong) UIView *bgView;
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UIImageView *iconImageView;
@end
@implementation HomeTableViewCell

//- (void)awakeFromNib {
//    [super awakeFromNib];
//    // Initialization code
//}
//重写init方法
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatabgView];
        //新建，添加到
        self.titleLabel = [UILabel new];
        [self.bgView addSubview:self.titleLabel];
        self.iconImageView = [UIImageView new];
        [self.bgView addSubview:self.iconImageView];
        //布局   topEqualToView 和某某一样      autoHeightRatio(0)自适应高度，
        self.iconImageView.sd_layout.topSpaceToView(self.bgView, 10).leftSpaceToView(self.bgView, 10).widthIs(70).heightIs(60);
        self.titleLabel.sd_layout.topEqualToView(self.iconImageView).leftSpaceToView(self.iconImageView, 10).rightSpaceToView(self.bgView, 10).autoHeightRatio(0);
        //设置cell行间距
        [self.bgView setupAutoHeightWithBottomViewsArray:@[self.iconImageView,self.titleLabel] bottomMargin:10];
        //设置行cell行间距
        [self setupAutoHeightWithBottomViewsArray:@[self.bgView] bottomMargin:5];
    }
    return self;
}
//设置浮起效果cell
-(void)creatabgView
{
    self.bgView = [UIView new];
    self.bgView.backgroundColor = [UIColor whiteColor];
    self.bgView.layer.shadowOffset = CGSizeMake(1, 1);
    self.bgView.layer.shadowOpacity = 0.3;
    self.bgView.layer.shadowColor = [UIColor blackColor].CGColor;
    [self.contentView addSubview:self.bgView];
    self.bgView.sd_layout.topSpaceToView(self.contentView,10).leftSpaceToView(self.contentView, 10).rightSpaceToView(self.contentView, 10);
}

//只要model传过来，就马上调用
- (void)setModel:(StroriesModel *)model
{
    _model = model;
    self.titleLabel.text = model.title;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.images.firstObject]];
}
//设置选中后的效果
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
   // [super setSelected:selected animated:animated];

    // Configure the view for the selected state
    //设置选中后只有cell的背景颜色改变
    self.bgView.backgroundColor = [UIColor whiteColor];
    if (selected) {
        self.bgView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1];
    }else
    {
        self.bgView.backgroundColor = [UIColor whiteColor];
}
}

@end
